package com.com.knowledgepaymentmanagementsystem.controller;

import com.com.knowledgepaymentmanagementsystem.controller.assets.AssetsController;
import com.com.knowledgepaymentmanagementsystem.pojo.courseshop.CourseShop;
import com.com.knowledgepaymentmanagementsystem.service.assets.AssetsService;
import com.com.knowledgepaymentmanagementsystem.service.bill.BillService;
import com.com.knowledgepaymentmanagementsystem.service.courseshop.CourseService;
import com.com.knowledgepaymentmanagementsystem.service.user.UserService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.experimental.FieldNameConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/27 下午4:59
 */
@Api(tags = "课程购买")
@RestController
@CrossOrigin
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private BillService billService;

    @Autowired
    private AssetsService assetsService;

    @Autowired
    private UserService userService;

    @ApiOperation(value = "课程查询",httpMethod = "GET",notes = "课程查询")
    @GetMapping("/getShop")
    public ResultUtil<List> getCourse(){

//       List list = courseService.getCourse();
        try {
            return new ResultUtil<>(200,"查询成功",courseService.getCourse());
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    @ApiOperation(value = "课程购买",httpMethod = "POST",notes = "课程购买")
    @PostMapping("/shop")
    public ResultUtil buyShop(@RequestBody CourseShop courseShop){
        try {
            billService.insertShopBills(courseShop);
            assetsService.insertShopAssets(courseShop);
            userService.updateShopUser(courseShop);
            return new ResultUtil<>(200,"购买成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"购买失败");
        }
    }
}
